package com.zmx.piglearn.utils

import android.content.Context
import android.widget.Toast

class SharedHelper(
    private val context: Context
) {

    fun save(username: String, password: String) {
        val sp = context.getSharedPreferences("mySharedPreference", Context.MODE_PRIVATE)
        val editor = sp.edit()
        editor.putString("username", username)
        editor.putString("password", password)
        editor.apply()
        Toast.makeText(context, "信息已写入 SharedPreference 中", Toast.LENGTH_SHORT).show()
    }

    fun read(): Map<String, String> {
        val sp = context.getSharedPreferences("mySharedPreference", Context.MODE_PRIVATE)
        return mapOf(
            "username" to sp.getString("username", "")!!,
            "password" to sp.getString("password", "")!!
        )
    }
}